home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / w00w00 / sectools / dsniff / asn1.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-16  |  680 b   |  55 lines

  1. /*
  2.   asn1.c
  3.  
  4.   Copyright (c) 2000 Dug Song <dugsong@monkey.org>
  5.   
  6.   $Id: asn1.c,v 1.1 2000/05/16 17:31:13 dugsong Exp $
  7. */
  8.  
  9. #include <sys/types.h>
  10. #include <arpa/nameser.h>
  11.  
  12. int
  13. asn1_type(u_char **buf)
  14. {
  15.     u_char *p = *buf;
  16.     int i;
  17.     
  18.     i = *p++ & 0x1f;
  19.     *buf = p;
  20.     
  21.     return (i);
  22. }
  23.  
  24. int
  25. asn1_len(u_char **buf)
  26. {
  27.     u_char *p;
  28.     int len, num = 0;
  29.     
  30.     p = *buf;
  31.     
  32.     if (*p >= 128) {    /* Long form */
  33.         len = *p++ & ~128;
  34.         
  35.         if (len == 1) {
  36.             num = *p++;
  37.         }
  38.         else if (len == 2) {
  39.             GETSHORT(num, p);
  40.         }
  41.         else if (len == 3) {
  42.             p--; GETLONG(num, p);
  43.             num &= 0xFFF;
  44.         }
  45.         else if (len== 4)
  46.             GETLONG(num, p);
  47.     }
  48.     else num = *p++;    /* Short form */
  49.     
  50.     *buf = p;
  51.     
  52.     return (num);
  53. }
  54.  
  55.